// @Bind #datasetQuery.onCreate
!function(datasetQuery) {
	//Initilize the query
	datasetQuery.insert();
}

//@Bind #datasetQueryDrawingId.onCreate
!function(datasetQueryDrawingId) {
	datasetQueryDrawingId.insert();
}


function flushDataset(dataset, param) {
	dataset.set("parameter", param);
	dataset.flush();
	dataset.notifyObservers();
}

//@Bind #buttonQuery.onClick
!function(buttonQuery, datasetQuery, datasetDemand) {
	var drawingId = datasetQuery.get("data:#.drawingId").replace("*", "%").toUpperCase();
	var batchNum = datasetQuery.get("data:#.batchNum").replace("*", "%").toUpperCase();
	var model = datasetQuery.get("data:#.model").replace("*", "%").toUpperCase();
	
	flushDataset(datasetDemand, {
		"drawingId" : drawingId,
		"batchNum" : batchNum,
		"model" : model
	});
}

//@Bind #buttonSave.onClick
!function(uActionUpdate) {
	uActionUpdate.execute();
}

//@Bind #buttonBreak.onClick
!function(uActionBreakDemand) {
	uActionBreakDemand.execute();
}

//@Bind #buttonQueryPart.onClick
!function(datasetPart, datasetQueryDrawingId) {
	var drawingId = datasetQueryDrawingId.get("data:#.drawingId");
	var part_name = datasetQueryDrawingId.get("data:#.partName")
	
	flushDataset(datasetPart, {
		"drawingId" : drawingId,
		"part_name" : part_name,
		"type" : "01"
	});
}

//@Bind #view.onCreate
!function(datasetDemand) {
	flushDataset(datasetDemand, {
		"drawingId" : "%",
		"batchNum" : "%",
		"model" : "%"
	});
}

//@Bind #dgVpart.onDataRowClick
!function(cdDrawingId, datasetDemand, arg){
	var record = datasetDemand.getData().current;
	//record.set("partUid", arg.data.get("partUid"));
	record.set("masterShopUid", arg.data.get("mastershopId"));
	record.set("routingUid", arg.data.get("routingId"));
	record.set("partDrawingId", arg.data.get("drawingId"));
	record.set("partVersionId", arg.data.get("versionId"));
	record.set("partName", arg.data.get("partName"));
	record.set("model", arg.data.get("model"));
	//record.set("masterShopUid", arg.data.get("routing_versionId"));
	record.set("masterShop.deptName", arg.data.get("mastershopName"));
	
	cdDrawingId.close(arg.data.get("drawingId"));
}

//@Bind #demandPilot.onSubControlAction
!function(demandPilot, arg, datasetDemand) {
	if('-' == arg.code) {
		arg.processDefault = false;
		var deleteList = new Array();
		//将被选择要删除的项放到数组中
		datasetDemand.getData().each(function(en){
			if(en.get("select") == true)
				deleteList.push(en);
		});
		//没有选择要删除的项
		if(0 == deleteList.length)
			alert("请选择要删除的项！");
		else if(confirm("确认删除吗?")) {
			deleteList.forEach(function(en){ 
				en.remove();
			});
		}
	}
	return false;
}


